package com.mystyle.le.weekproject.asynctaks;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

import com.mystyle.le.weekproject.intentfactbackcall.MyCallBack;
import com.mystyle.le.weekproject.utils.DownData;

/**
 * 下载图片任务
 * Created by le on 2016/10/9.
 */
public class PictureAsyncTaks extends AsyncTask<String,Void,byte[]> {
    private String path;
    private MyCallBack.DownPicture downPicture;
    private Context context;

    public PictureAsyncTaks(MyCallBack.DownPicture downPicture, Context context) {
        this.downPicture = downPicture;
        this.context = context;
    }

    @Override
    protected byte[] doInBackground(String... params) {
        boolean netWorkConn = DownData.isNetWorkConn(context);
        if (netWorkConn){
            path = params[0];
            return DownData.downData(path);
        }
      return null;
    }

    @Override
    protected void onPostExecute(byte[] bytes) {
        super.onPostExecute(bytes);
        if (bytes!=null&&bytes.length>0){
            downPicture.downPicture(bytes,path);
        }
    }
}
